import axios from 'axios';

const apiClient = axios.create({
  baseURL: 'http://localhost:3000/api',
  timeout: 10000,
});

// 登录接口
export const login = async (realname, password) => {
  try {
    const response = await apiClient.post('/login', { realname, password });
    return response.data;
  } catch (error) {
    console.error("API请求失败:", error);
    return null; // 或者返回默认值
  }
};
// 获取科室列表接口
export const getDeptList = async () => {
  try {
    const response = await apiClient.get('/getDeptList');
    return response.data;
  } catch (error) {
    console.error("API请求失败:", error);
    return null; // 或者返回默认值
  }
};
// 获取已完成闭环列表接口
export const getCloseOkList = async () => {
  try {
    const response = await apiClient.get('/getCloseOkList');
    return response.data;
  } catch (error) {
    console.error("API请求失败:", error);
    return null; // 或者返回默认值
  }
};
// 获取住院患者列表接口

export const getInOutHospList = async (params) => {
  try {
    // 使用 apiClient，基础路径自动生效
    const response = await apiClient.get('/getInOutHospList', { params });
    return response.data;
  } catch (error) {
    console.error("API请求失败:", error);
    return null;
  }
};

// 获取闭环列表接口
export const getAllCloseLoopList = async (params) => {
  try {
    const response = await apiClient.get('/getAllCloseLoopList', { params });
    return response.data;
  } catch (error) {
    console.error("API请求失败:", error);
    return null;
  }
};

//获取闭环基本信息接口
export const getCloseLoopDetailJb = async (params) => {
  try {
    const response = await apiClient.get('/getCloseLoopDetailJb', { params });
    return response.data;
  } catch (error) {
    console.error("API请求失败:", error);
    return null;
  }
};
//获取闭环基本信息中用户列表接口
export const getUserInfo = async (params) => {
  try {
    const response = await apiClient.get('/getUserInfo', { params });
    return response.data;
  } catch (error) {
    console.error("API请求失败:", error);
    return null;
  }
};

//获取闭环医嘱信息接口
export const getCloseLoopDetailYz = async (params) => {
  try {
    const response = await apiClient.get('/getCloseLoopDetailYz', { params });
    return response.data;
  } catch (error) {
    console.error("API请求失败:", error);
    return null;
  }
};
//获取闭环医嘱信息接口
export const getCloseLoopDetailYzBase = async (params) => {
  try {
    const response = await apiClient.get('/getCloseLoopDetailBase', { params });
    return response.data;
  } catch (error) {
    console.error("API请求失败:", error);
    return null;
  }
};
//获取闭环主医嘱字段接口
export const getCloseLoopDetailYzColumn = async (params) => {
  try {
    const response = await apiClient.get('/getCloseLoopDetailYzColumn', { params });
    return response.data;
  } catch (error) {
    console.error("API请求失败:", error);
    return null;
  }
};

//获取闭环节点列表

export const getCloseLoopDetail= async (params) => {
  try {
    const response = await apiClient.get('/getCloseLoopDetail', { params });
    return response.data;
  } catch (error) {
    console.error("API请求失败:", error);
    return null;
  }
};
//
//获取闭环的明细节点的字段列表
export const getCloseLoopDetailNodes= async (params) => {
  try {
    const response = await apiClient.get('/getCloseLoopDetailNodes', { params });
    return response.data;
  } catch (error) {
    console.error("API请求失败:", error);
    return null;
  }
};
//获取闭环的明细节点的字段列表
export const getCloseLoopDetailColumn= async (params) => {
  try {
    const response = await apiClient.get('/getCloseLoopDetailColumn', { params });
    return response.data;
  } catch (error) {
    console.error("API请求失败:", error);
    return null;
  }
};

